home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 May / PCWMAY06.iso / Software / Freeware / First Page 2006 3.00 / fp2006-final-3.00-setup.exe / {app} / Iscripts / Maths & Calculations / length-converter.izs < prev    next >
Text File  |  2005-07-29  |  6KB  |  181 lines

  1. <!NOWIZARD>
  2.  
  3. <!TITLE>Length Converter
  4. <!/TITLE>
  5.  
  6. <!DESCRIPTION>Use this practical script to easily convert between the 7 most popular length units- centimeters, meters, kilometers, miles, inches, feet and yards. Simply enter a number, and let the script display the desired equivalents.
  7. <!/DESCRIPTION> 
  8.  
  9. <!CATEGORY>math related<!/CATEGORY>
  10.  
  11. <!SCRIPT>
  12. <!-- START OF SCRIPT -->
  13. <script type="text/javascript">
  14.  
  15. var factors1 = new Array(1, 0.01, 0.00001, 0.00000621, 0.3937, 0.0328, 0.01094);
  16. var factors2 = new Array(100, 1, 0.001, 0.000621, 39.37, 3.28,  1.094);
  17. var factors3 = new Array(100000, 1000, 1, 0.621, 39370, 3280, 1094);
  18. var factors4 = new Array(160934, 1609.34, 1.60934, 1, 63360, 5280,1760);
  19. var factors5 = new Array(2.54, 0.0254, 0.0000254, 0.0000158, 1, 0.08333, 0.02778);
  20. var factors6 = new Array(30.48, 0.3048, 0.0003048, 0.0001896, 12, 1, 0.3333);
  21. var factors7 = new Array(91.44, 0.9144, 0.0009144, 0.0005688, 36, 3, 1);
  22. var factors = new Array(factors1,factors2,factors3,factors4,factors5,factors6,factors7);
  23.  
  24. function convert_unit()
  25. {
  26.     from_index = document.length_con.from_unit.selectedIndex;
  27.     to_index = document.length_con.to_unit.selectedIndex;
  28.     factor = factors[from_index][to_index];
  29.     document.getElementById("formula").innerHTML = document.length_con.from_unit.options[document.length_con.from_unit.selectedIndex].text + " = " + factor + " " + document.length_con.to_unit.options[document.length_con.to_unit.selectedIndex].text;
  30.     if(isNaN(document.length_con.from_value.value))
  31.         document.getElementById("to_value").innerHTML = "Not a valid number.";
  32.     else
  33.         document.getElementById("to_value").innerHTML = factor * document.length_con.from_value.value;
  34. }
  35. </script>
  36.  
  37. <h2>Length Converter</h2>
  38. <p>
  39. <b>1</b> select a length unit from the "From" dropdown list and one from the "To" dropdown list.
  40. <br><b>2</b> Enter a numeric value, and click "To" button.
  41. <p><form name="length_con">
  42.  
  43. <table>
  44.  
  45.     <tr>
  46.         <td>From </td>
  47.  
  48.         <td>
  49.             <select name=from_unit onChange="convert_unit()";>
  50.             <option> centimeters
  51.             <option> meters
  52.             <option> kilometers
  53.             <option> miles
  54.             <option> inches
  55.             <option> feet
  56.             <option> yards
  57.             </select>
  58.  
  59.         </td>
  60.         <td>  To </td>
  61.         <td>
  62.             <select name=to_unit onChange="convert_unit()";>
  63.             <option> centimeters
  64.             <option> meters
  65.             <option> kilometers
  66.             <option> miles
  67.             <option> inches
  68.             <option> feet
  69.             <option> yards
  70.             </select>
  71.  
  72.         </td>
  73.     </tr>
  74.     <tr>
  75.         <td> </td><td colspan="3"><div id="formula">centimeters = 1 centimeters</div></td>
  76.     </tr>
  77.  
  78.     <tr>
  79.         <td colspan="4"> </td>
  80.     </tr>
  81.  
  82.     <tr>
  83.         <td>Enter </td>
  84.         <td><input type="text" name="from_value" value="1" size="12" maxlength="12"></td>
  85.         <td> <input type=button value="To" onClick="convert_unit()";> </td>
  86.         <td><div id="to_value">1</div></td>
  87.     </tr>
  88.  
  89. </table>
  90.  
  91. </form>
  92. <!-- END OF SCRIPT -->
  93. <!/SCRIPT>
  94.  
  95. <!PREVIEW>
  96. <!-- START OF SCRIPT -->
  97. <script type="text/javascript">
  98.  
  99. var factors1 = new Array(1, 0.01, 0.00001, 0.00000621, 0.3937, 0.0328, 0.01094);
  100. var factors2 = new Array(100, 1, 0.001, 0.000621, 39.37, 3.28,  1.094);
  101. var factors3 = new Array(100000, 1000, 1, 0.621, 39370, 3280, 1094);
  102. var factors4 = new Array(160934, 1609.34, 1.60934, 1, 63360, 5280,1760);
  103. var factors5 = new Array(2.54, 0.0254, 0.0000254, 0.0000158, 1, 0.08333, 0.02778);
  104. var factors6 = new Array(30.48, 0.3048, 0.0003048, 0.0001896, 12, 1, 0.3333);
  105. var factors7 = new Array(91.44, 0.9144, 0.0009144, 0.0005688, 36, 3, 1);
  106. var factors = new Array(factors1,factors2,factors3,factors4,factors5,factors6,factors7);
  107.  
  108. function convert_unit()
  109. {
  110.     from_index = document.length_con.from_unit.selectedIndex;
  111.     to_index = document.length_con.to_unit.selectedIndex;
  112.     factor = factors[from_index][to_index];
  113.     document.getElementById("formula").innerHTML = document.length_con.from_unit.options[document.length_con.from_unit.selectedIndex].text + " = " + factor + " " + document.length_con.to_unit.options[document.length_con.to_unit.selectedIndex].text;
  114.     if(isNaN(document.length_con.from_value.value))
  115.         document.getElementById("to_value").innerHTML = "Not a valid number.";
  116.     else
  117.         document.getElementById("to_value").innerHTML = factor * document.length_con.from_value.value;
  118. }
  119. </script>
  120.  
  121. <h2>Length Converter</h2>
  122. <p>
  123. <b>1</b> select a length unit from the "From" dropdown list and one from the "To" dropdown list.
  124. <br><b>2</b> Enter a numeric value, and click "To" button.
  125. <p><form name="length_con">
  126.  
  127. <table>
  128.  
  129.     <tr>
  130.         <td>From </td>
  131.  
  132.         <td>
  133.             <select name=from_unit onChange="convert_unit()";>
  134.             <option> centimeters
  135.             <option> meters
  136.             <option> kilometers
  137.             <option> miles
  138.             <option> inches
  139.             <option> feet
  140.             <option> yards
  141.             </select>
  142.  
  143.         </td>
  144.         <td>  To </td>
  145.         <td>
  146.             <select name=to_unit onChange="convert_unit()";>
  147.             <option> centimeters
  148.             <option> meters
  149.             <option> kilometers
  150.             <option> miles
  151.             <option> inches
  152.             <option> feet
  153.             <option> yards
  154.             </select>
  155.  
  156.         </td>
  157.     </tr>
  158.     <tr>
  159.         <td> </td><td colspan="3"><div id="formula">centimeters = 1 centimeters</div></td>
  160.     </tr>
  161.  
  162.     <tr>
  163.         <td colspan="4"> </td>
  164.     </tr>
  165.  
  166.     <tr>
  167.         <td>Enter </td>
  168.         <td><input type="text" name="from_value" value="1" size="12" maxlength="12"></td>
  169.         <td> <input type=button value="To" onClick="convert_unit()";> </td>
  170.         <td><div id="to_value">1</div></td>
  171.     </tr>
  172.  
  173. </table>
  174.  
  175. </form>
  176.  
  177.  
  178. <!-- END OF SCRIPT -->
  179. <!/PREVIEW>
  180.  
  181. <!RELATED>NONE<!/RELATED>